#-*-coding:utf-8-*-
import os
import datetime


#截图函数
def insert_img(driver,file_name):
    base_dir=os.path.dirname(os.path.dirname(__file__))
    base_dir=str(base_dir)
    base_dir=base_dir.replace('/','\\')
    base=base_dir.split('test_case')[0]
    file_path=base+"\\report\\image\\"+file_name
    driver.get_screenshot_as_file(file_path)


#获取当前时间字符串函数
def getCurrentTime():
    dateCurrent=datetime.datetime.now().strftime('%Y%m%d_%H%M%S')  # 现在
    return dateCurrent
#获取当前时间字符串函数
def writeErrorLog(errorMsg):
    errorMsg=getCurrentTime()+'\n'+errorMsg+'\n'
    try:
        f = open("D:/logs/seleniumError.txt",'a+')
    except Exception as e:
        print "File is not found."
    f.write(errorMsg)
def printPageSource(dr,sourcename):
    print(dr.page_source)
    sourcename=os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + '//FunctionClass//'+sourcename+'.html'
    if(os.path.exists(sourcename)):
        os.remove(sourcename)
    f = open(sourcename, 'a+')
    f.write(dr.page_source)
    return sourcename
if __name__=='__main__':
    writeErrorLog("abc")
